var allFields = new Array();
var ctrl = false;
var alt = false;
var shift = false;
var visible = false;
/*
var Settings = new Array();
var port = chrome.extension.connect({
    name: "Hidden-Field Switcher"
});
port.postMessage("Settings");
port.onMessage.addListener(function(recSettings) {
    Settings = recSettings;
});
*/

function hotkey_keydown_handler(e) {
    var keyCode = e.keyCode;
    if (keyCode == 17)
        ctrl = true;
    if (keyCode == 16)
        shift = true;
    if (keyCode == 18)
        alt = true;

    if(ctrl == true && shift == true && keyCode == 83) {
        switchHidden();

        //ctrl = false;
        //shift = false;
        //alt = false;
    }
}
function hotkey_keyup_handler(e) {
    var keyCode = e.keyCode;
    if (keyCode == 17)
        ctrl = false;
    if (keyCode == 16)
        shift = false;
    if (keyCode == 18)
        alt = false;
}

document.onkeydown = hotkey_keydown_handler;
document.onkeyup = hotkey_keyup_handler;

//document.body.onmouseover = showHidden;
// document.body.onmouseout = hideHidden;
//allForms[Key].onmouseover = showHidden;
//allForms[Key].onmouseout = hideHidden;

function switchHidden() {
    if(visible == true){
        hideHidden();
        visible = false;
    }
    else {
        showHidden();
        visible = true;

    }

}
function showHidden() {
    var allHidden = document.getElementsByTagName("input");
    for (var Key in allHidden) {
        if(allHidden[Key].type == "hidden") {
            allFields.push(allHidden[Key]);
            allHidden[Key].type = "text";

            /*for (var SettingsKey in Settings) {
                var subSection = SettingsKey.substring(7,0);
                var subKey = SettingsKey.substring(7);
                if(subSection == "styles_") {
                    allHidden[Key].style.setProperty(subKey,Settings[SettingsKey]);
                }
            }*/
            
            if(allHidden[Key].name)
                allHidden[Key].title = allHidden[Key].name;
            if(!allHidden[Key].name && allHidden[Key].id)
                allHidden[Key].title = allHidden[Key].id;
            allHidden[Key].style.setProperty("background-color","#CCFFFF");
        }
    }
}

function hideHidden() {
    for (var Key in allFields) {
        allFields[Key].type = "hidden";
    }
    allFields = new Array();
}